import yagmail

mail_address = "18298600927@163.com"
mail_host = "smtp.163.com"
mail_port = 465
mail_password = "TYUOQTLWBNNDAFSZ"

def sendmail(to_user: list, 
             subject: str, 
             text: str, 
             att=None):
    if isinstance(to_user, (str, list)) and isinstance(subject, str) and isinstance(text, str):
        ## 初始化邮件服务器对象
        smtp = yagmail.SMTP(user=mail_address,
                     password=mail_password,
                     host=mail_host,
                     port=mail_port,
                     smtp_ssl=True)
        smtp.send(to=to_user, subject=subject, contents=text, attachments=att)
    else:
        raise TypeError("参数类型错误")
data = '''
小鱼快游，四面八方都是自由
'''
sendmail(to_user=mail_address, subject="python实训", text=data, att="/root/text/xin.jpg")
